package com.xunfang.config;

import com.xunfang.interception.LoginInterception;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author yellow Docter
 * @date 2023 -10-26
 * @desc
 *
 *  1、实现mvc的配置接口    (springboot项目整合 拦截器提供的额外配置)
 *  2、注入 拦截器  private LoginInterception loginInterception;
 *  3、配置拦截器
 *       需要拦截器谁
 *       拦截规则
 */
@Configuration  //配置类
public class LoginInterceptionConfig implements  WebMvcConfigurer {

    @Autowired
    private LoginInterception loginInterception;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 注册拦截器：告诉springboot那个类是拦截器
         */
        registry.addInterceptor(loginInterception)
                .addPathPatterns("/**")//拦截所有请求
                .excludePathPatterns(    //哪些请求我要放行
                        "/user/login",   //登录放行
                        "/user/testLogin1",  //放行 不登录也可以访问

                        "/**/*.js",   //下面的静态资源我要放行
                        "/**/*.css",
                        "/**/*.ico",
                        "/**/*.html",
                        "/**/*.jpg",
                        "/**/*.png",
                        "/error",
                        "/**/*.min.map",
                        "/swagger-resources",
                        "/v3/api-docs",
                        "/v2/api-docs",
                        "/js/**",
                        "/css/**",
                        "/images/**",
                        "/img/**",
                        "/plugins/**"
                );
    }

}
